<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<?php
include("../models/webconfig.php");
include("../models/class.connection.php");
include ("../models/entities/class.AccountEntity.php");
include ("../models/repositories/class.AccountRepository.php");
@session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
    </head>
    <body>
        <center>
            <table border="0px" style="background-color:#0f0f0f " >
                <tr style="height: 300px;">
                    <td  colspan="3" style="width: 1000px"><img src="../content/images/banner.jpg"/></td>

                </tr>
                <tr style="height: 300px">
                    <td style="width:300px">
                        <div style="height: 20px"><a href="../views/Admin_login.php?logout=TRUE" style="text-decoration: none" >Quay lại trang đăng nhập</a></div>
                        <div style="height: 279px"></div>
                    </td>
                    <td style="width:300px;background-color:#aaaaaa ;border:#0099FF" >
                        <center>
                            <div style="height: 70px;margin-top: 0px;"> <h1 style="color: #2B6FB6;padding-bottom: 0px">Get PassWord</h1></div>
                            <form action="backend.forgotpassword.php" method="post">
                                <div style="height: 130px;width: 300px">
                                    Nhập Vào Tài Khoản:<input type="text" name="Username"><br/><br/>
                                    Nhập Mật Khẩu mới:<input type="password" name="Newpass"><br/><br/>
                                    <img src="../library/quickcaptcha/imagebuilder.php?rand=' . rand(0,999999) . '" border="1"><br/><br/>
                                    Nhập mã kiểm tra:<input type="text" name="captcha"><br/><br/>
                                    <input type="submit" name="sendMail" value="Send Mail">
                                    <?php
                                    if (isset($_POST["Username"]) && isset($_POST["Newpass"])) {
                                        if ($_POST['captcha'] == $_SESSION['string']) {
                                            $respon = new AccountRepository();
                                            $kq = $respon->GetAccountByUserName($_POST["Username"]);
                                            if ($kq) {
                                                $bool = $respon->UpdatePassword($_POST["Username"], md5($_POST["Newpass"]));
                                                if ($bool) {
                                                    require_once("../library/phpmailer/class.phpmailer.php");
                                                    $mail = new PHPMailer();
                                                    $mail->IsSMTP();
                                                    $mail->SMTPAuth = true;
                                                    $mail->SMTPSecure = 'ssl';
                                                    $mail->Username = "cactusdlu@gmail.com";
                                                    $mail->Password = "it.dlu.edu.vn";
                                                    $mail->From = "admin.salemflower@gmail.com";
                                                    $mail->FromName = "Salem Flower";
                                                    $mail->AddAddress($kq->Email_s);
                                                    $mail->AddReplyTo("admin.salemflower@gmail.com", "October");
                                                    $mail->WordWrap = 50;
                                                    $mail->IsHTML(true);
                                                    $mail->Subject = "Lấy lại Password";
                                                    $body = "Password mới của bạn là:" . $_POST["Newpass"];
                                                    $mail->Body = $body;
                                                    if (!$mail->Send()) {
                                                        echo "Mailer Error: " . $mail->ErrorInfo;
                                                    } else {
                                                        echo"<p style='color:red'>Mật Khẩu đã được gửi vào mail của bạn.</p>";
                                                    }
                                                }
                                            } else {
                                                echo"<p style='color:red'>Nhập sai Tài Khoản</p>";
                                            }
                                        } else {
                                            echo "<p style='color:red'>nhập mã chưa chính xác</p>";
                                        }
                                    }
                                    ?>

                                </div>
                            </form>
                        </center>
                    </td>
                    <td style="width:300px;"></td>
                </tr>
                <tr style="height: 170px">
                    <td style="width:300px"></td>
                    <td style="width:300px"></td>
                    <td style="width:300px"></td>
                </tr>
            </table>
        </center>
        <?php
// put your code here
        ?>
    </body>
</html>
